import React from 'react'
import {render} from 'react-dom'
import {Router, Route, IndexRoute} from 'react-router'
import View from 'lib/View.jsx'
import Layout from '../common/layout.jsx'
import RootView from './RootView.jsx'
import DetailView from './DetailView.jsx'
import moment from 'moment'
import history from '../common/history.es6';

class MainView extends View {
  constructor(props, context) {
    super(props, context);

    this.releaseDate = moment('2015-11-26');
  }

  render(){
    let subTitle = '卡顿页面情况' + (moment().valueOf() > this.releaseDate.add(60, 'days').valueOf() ? '' : '（Beta）');

    return (
      <Layout title="卡顿" subtitle={subTitle}>
        { React.cloneElement(this.props.children, { routeParams: this.props.params, key: this.getHandlerKey() }) }
      </Layout>
    )
  }
}

render((
  <Router history={ history }>
    <Route path="/" component={MainView}>
      <Route path="/:id" component={DetailView} />
      <IndexRoute component={RootView} />
    </Route>
  </Router>
), document.getElementById('root'));
